class Device(object):
    pass
    
class ETHDevice(Device):
    def __init__(self, hw, tdev, network = 'default', mode = 'nat',
                 ip = None):
        self.hw = hw.upper()
        self.tdev = tdev
        self.mode = mode
        self.network = network
        self.ip = ip
    
    def toxml(self, root):
        with root('interface', type='network'):
            root << ('source', {'network': self.network})
            root << ('forward', {'mode':self.mode})
            root << ('target', {'dev':self.tdev})
            root << ('mac', {'address':self.hw})
            
class HDDFileDevice(Device):
    def __init__(self, image_path,
                       type_ = 'raw',
                       driver='qemu',
                       device='disk',
                       dev = 'vda',
                       bus = 'virtio'):
        self.image_path = image_path
        self.type_ = type_
        self.driver = driver
        self.device = device
        self.dev = dev
        self.bus = bus

    @classmethod
    def cdrom(cls, path):
        return cls(path, 'file', device = 'cdrom', dev = 'vdc')

    def toxml(self, root):
        with root('disk', device=self.device, type='file'):
            root << ('driver', {'type' : self.type_, 
                                'name' : self.driver})
            root << ('source', 
                {'file': self.image_path})
            
            root.boot
            
            root << ('target', {'bus':self.bus, 'dev' : self.dev})

